﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Model;

namespace LOPA
{
    public partial class EventLibraryForm : Form {
        private List<Event> _allEvents = GetEventList();
        public EventLibraryForm()
        {
            InitializeComponent();
        //    LoadData();
            dgvEventList.AllowUserToAddRows = false;
            _bindEvent.DataSource = _allEvents;
            dgvEventList.DataSource = _bindEvent;
        }

        private static List<Event> GetEventList() {
            return DataAccess.CSVHelper.GetEventList("./Config/Events.xls", "Events");
        }

        private void tbxKey_TextChanged(object sender, EventArgs e) {
           string key = tbxKey.Text;
            if (key == "") {
                _bindEvent.DataSource = GetEventList();
                _bindEvent.ResetBindings(false);
                return;
            }
            List<Event> list = _bindEvent.DataSource as List<Event>;
            List<Event> newList = new List<Event>();
            foreach (Event et in list) {
                if (et.Title.Contains(key) || et.Desc.Contains(key)||et.Reason.Contains(key)||et.Advice.Contains(key)) {
                    newList.Add(et);
                }
            }
            _bindEvent.Clear();
            _bindEvent.DataSource = newList;
        }
    }
}
